package com.eamois.util;

//import org.apache.log4j.Logger;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.Resource;

public class ServiceFactory {
	private static final Logger log = Logger.getLogger(ServiceFactory.class);

	private static BeanFactory beanFactory;

	private static ServiceFactory instance;

	static {
		initialize();
	}

	public static ServiceFactory getInstance() {
		if (instance == null)
			instance = new ServiceFactory();
		return instance;
	}

	private static void initialize() {
		try {
			FileSystemResourceLoader loader = new FileSystemResourceLoader();
			Resource rs = loader.getResource("classpath:springContext.xml");
			beanFactory = new XmlBeanFactory(rs);
		} catch (Exception e) {
			log.error(e);
		}
	}

	public Object getBean(String beanName) {
		return beanFactory.getBean(beanName);
	}
}
